<include file="Map:nav" />
<div>
    <div id="mapLeft" class="mapLeft">
        <div class="h_m_l">
           <div class="nav_div1"><p>位置: <a href="/">首页</a> > <a href="{:U('House/index')}">新房</a> > {$house.title}</p></div>
           <div class="map_h_i">
               <div class="h_i1">
                   <a target="_blank" title="{$house.title}" href="{:U('House/detail',array('id'=>$house['id']))}"><img width="108" height="82" alt="{$house.title}" src="{$house['logo'] ? $house['logo'] : $house['img']}"></a>
                   <h1><a target="_blank" title="{$house.title}" href="{:U('House/detail',array('id'=>$house['id']))}">{$house.title}</a></h1>
                   <p>均价: <span class="h_c_b">{$house.average_price}元/㎡</span></p>
                   <p>电话: <span class="h_c_b">{$house_tel[0]} 转 {$house_tel[1]}</span></p>
               </div>
               <div class="line"></div>
               <div class="h_a1"><span class="h_c_b">地址:</span> {$house_add[0]} {$house_add[1]}</div>
               <div class="line"></div>
               <div>
                   <ul>
                       <li><a title="{$house.title}主页" target="_blank" href="{:U('House/detail',array('id'=>$house['id']))}">主页</a></li>
                       <li><a title="{$house.title}详细" target="_blank" href="{:U('House/info',array('hid'=>$house['id']))}">详细</a></li>
                       <li><a title="{$house.title}户型" target="_blank" href="{:U('House/type',array('hid'=>$house['id']))}">户型</a></li>
                       <li><a title="{$house.title}图片" target="_blank" href="{:U('House/pic',array('hid'=>$house['id']))}">图片</a></li>
                       <li><a title="{$house.title}动态" target="_blank" href="{:U('House/news',array('hid'=>$house['id']))}">动态</a></li>
                       <li><a title="{$house.title}价格" target="_blank" href="{:U('House/price',array('hid'=>$house['id']))}">价格</a></li>
                       <li><a title="{$house.title}问答" target="_blank" href="{:U('House/ask',array('hid'=>$house['id']))}">问答</a></li>
                   </ul>
               </div>
           </div>
            <div class="line"></div>
            <div class="h_i_div">
                <label>独家优惠:</label>
                {$house.coupons}
            </div>
            <div class="h_i_div">
                <label>优点:</label>
                {$house_data.special}
            </div>
            <div class="h_i_div">
                <label>缺点:</label>
                {$house_data.shortcoming}
            </div>
        </div>
    </div>
    <div id="mapRight" class="mapRight" style="position: relative"></div>
</div>

<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak={$ak}"></script>
<script type="text/javascript">
    //javascript的数组扩展方法
    Array.prototype.contains = function (obj) {
        var i = this.length;
        while (i--) {
            if (this[i] === obj) {
                return true;
            }
        }
        return false;
    }
</script>
<script>
    $(document).ready(function () {
        $("#mapWrap").height($(window).height());
        $(window).resize(function () {
            $("#mapWrap").height($(window).height());
        });
        $('#mapLeft,#mapRight').css('height', $(window).height() - 60);
        $(window).resize(function () {
            $('#mapLeft,#mapRight').css('height', $(window).height() - 60);
        });
        $('.mapList').css('height', $(window).height() - 258);
        $(window).resize(function () {
            $('.mapList').css('height', $(window).height() - 258);
        });
    });

</script>
<script type="text/javascript">
    var height = document.documentElement.clientHeight;
    var width = document.documentElement.clientWidth;
    var lvjupath ="http://" + window.location.host;
    var houseID = ""; //缓存已经加载过的楼盘ID，以字符串形式，ID间用逗号相隔
    // 百度地图API功能
    var mp = new BMap.Map("mapRight", { enableMapClick: false });
    mp.centerAndZoom(new BMap.Point(110.31327, 20.030473), 15);
    mp.addControl(new BMap.NavigationControl());               // 添加平移缩放控件
    mp.addControl(new BMap.ScaleControl());                    // 添加比例尺控件

    mp.addControl(new BMap.OverviewMapControl());              // 添加缩略地图控件
    mp.enableScrollWheelZoom(); 							   // 启用滚轮放大缩小
    var positions = new Array("0", "-20", "-10", "-30");
    var backgroundColors = new Array("#33C0D0", "#fc5172", "#ff9600", "#9e9e9e");
    var borders = new Array("#0D5780", "#CC0066", "#FF6600", "#4B4B4B");

    function ComplexCustomOverlay(point_lng, point_lat, text, mouseoverText, type, bid, address, path, phone1, discount) {
        this._point = new BMap.Point(point_lng, point_lat);
        this._text = text;
        this._overText = mouseoverText;
        this._type = getType(type);
        this._y_type = type;
        this._bid = bid;
        this._point_lng = point_lng;
        this._point_lat = point_lat;
        this._address = address;
        this._path = path;
        this._phone1 = phone1;
        this._discount = discount;
    }
    ComplexCustomOverlay.prototype = new BMap.Overlay();
    ComplexCustomOverlay.prototype.initialize = function (map) {
        this._map = map;
        var div = this._div = document.createElement("div");
        div.style.position = "absolute";
        div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
        div.style.backgroundColor = backgroundColors[this._type];
        div.style.border = "1px solid " + borders[this._type];
        div.style.color = "white";
        div.style.height = "18px";
        div.style.padding = "2px";
        div.style.cursor = "pointer";
        div.style.lineHeight = "18px";
        div.style.whiteSpace = "nowrap";
        div.style.MozUserSelect = "none";
        div.style.fontSize = "12px"
        var span = this._span = document.createElement("span");
        div.appendChild(span);
        //调整地图楼盘初始显示价格
        span.appendChild(document.createTextNode(this._overText));
        var that = this;
        var arrow = this._arrow = document.createElement("div");
        arrow.style.background = "url(__IMG__/label.png) no-repeat";
        arrow.style.backgroundPosition = "0px " + positions[this._type] + "px";
        arrow.style.position = "absolute";
        arrow.style.width = "11px";
        arrow.style.height = "10px";
        arrow.style.top = "22px";
        arrow.style.left = "10px";
        arrow.style.overflow = "hidden";
        div.appendChild(arrow);
        div.onmouseover = function () {
            map_mouseover(div, arrow, that);
        }
        div.onmouseout = function () {
            map_mouseout(div, arrow, that);
        }
        //20和21 用于网上售楼处地图交通里面的显示, 不需要onclick事件
        if (this._y_type != 21 && this._y_type != 20 && this._y_type != 19) {
            div.onclick = function () {
                select_point = new BMap.Point(that._point_lng, that._point_lat);
                select_bid = that._bid;
                select_bname = that._text;
                select_path = that._path;
                select_address = that._address;
                select_type = that._y_type;
                select_overText = that._overText;
                select_phone1 = that._phone1;
                select_discount = that._discount;
                select_price = select_overText.replace(select_bname, "");
                fang_cms_oncilck();
            }
        }
        mp.getPanes().labelPane.appendChild(div);
        return div;
    }
    ComplexCustomOverlay.prototype.draw = function () {
        var map = this._map;
        var pixel = map.pointToOverlayPixel(this._point);
        this._div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px";
        this._div.style.top = pixel.y - 30 + "px";
    }
    function getType(type) {
        if (type == 2 || type == 21) {
            return 1;
        } else if (type == -1) {
            return 3;
        } else {
            return 0;
        }
    }
    function map_mouseover(div, arrow, that) {
        div.style.backgroundColor = backgroundColors[2];
        $(div).css("z-index", "9999");
        div.style.borderColor = borders[2];
        div.getElementsByTagName("span")[0].innerHTML = that._overText;
        arrow.style.backgroundPosition = "0px " + positions[2] + "px";
    }
    function map_mouseout(div, arrow, that) {
        div.style.backgroundColor = backgroundColors[that._type];
        $(div).css("z-index", "1");
        div.style.borderColor = borders[that._type];
        //鼠标移出后楼盘显示内容不变

        div.getElementsByTagName("span")[0].innerHTML = that._overText;
        arrow.style.backgroundPosition = "0px " + positions[that._type] + "px";
    }

    function get_url($k){
        if($k=='detail'){
            var url = "{:U('House/detail',array('id'=>'@id@'))}";
        }
        if($k=='pic'){
            var url = "{:U('House/pic',array('hid'=>'@id@'))}";
        }
        if($k=='info'){
            var url = "{:U('House/info',array('hid'=>'@id@'))}";
        }
        if($k=='type'){
            var url = "{:U('House/type',array('hid'=>'@id@'))}";
        }
        if($k=='price'){
            var url = "{:U('House/price',array('hid'=>'@id@'))}";
        }
        if($k=='ask'){
            var url = "{:U('House/ask',array('hid'=>'@id@'))}";
        }
        if($k=='news'){
            var url = "{:U('House/news',array('hid'=>'@id@'))}";
        }
        url = decodeURIComponent(url);
        url = url.replace('@id@',select_bid);
        return url;
    }

    function fang_cms_oncilck() {
        msgwindow = 1;
        var add = select_address.split('|');
        var  address = add[1];
        var t = select_phone1.split('|');
        var tel = t[0]+'转'+t[1];
        var phone = "<span style='color:#FF6400'><strong>" + tel + "</strong></span>";
        var sContent = "<div style='width:400px;'>";
        sContent += "<div style='float:left;width:100px; padding:30px 10px 0px 0px;overflow:hidden;'><img src=\"" + select_path + "\" style='width:100px;height:71px;'></div>";
        sContent += "<div style='width:290px;overflow:hidden;'>";
        sContent += "<h4>";
        sContent += "<a href='"+get_url('detail')+"' target='_blank' style='color:#006699;'>" + select_bname + "</a></h4>";
        sContent += "<p style='margin:0;line-height:22px;color:#999;'>参考均价：<span style='color:#FF6400;'><strong>" + (select_price == '' ? '  预登记' : select_price + "元/㎡") + "</strong></span></p>";
        if (select_phone1 != "") sContent += "<p style='margin:0;line-height:22px;color:#999;'>免费电话：<span id='phone' style='color:#333;'>" + phone + "</span></p>";
        if (select_discount != "") sContent += "<p style='margin:0;line-height:22px;color:#999;'>优惠信息："+select_discount+"</p>";
        sContent += "<p style='margin:0;line-height:22px;color:#999;'>楼盘地址：<span id='address_" + select_bid + "' style='color:#333;'>" + address + "</span></p>";
        sContent += "<p style='color:#006699;'></p>";
        if(select_type = '22'){
            sContent += "<p style='margin:0;line-height:22px;color:#999;'>" +
                    "<span ><a style='color:#006699;' href='"+get_url('detail')+"' target='_blank'>主页</a>&nbsp;&nbsp;" +
                    "<span ><a style='color:#006699;' href='"+get_url('info')+"' target='_blank'>详细</a>&nbsp;&nbsp;" +
                    "<span ><a style='color:#006699;' href='"+get_url('type')+"' target='_blank'>户型</a>&nbsp;&nbsp;" +
                    "<span ><a style='color:#006699;' href='"+get_url('pic')+"' target='_blank'>图片</a>&nbsp;&nbsp;" +
                    "<span ><a style='color:#006699;' href='"+get_url('news')+"' target='_blank'>动态</a>&nbsp;&nbsp;" +
                    "<span ><a style='color:#006699;' href='"+get_url('price')+"' target='_blank'>价格</a>&nbsp;&nbsp;" +
                    "<span ><a style='color:#006699;' href='"+get_url('ask')+"' target='_blank'>问答</a>&nbsp;&nbsp;" +
                    "</span></p>";
        }
        sContent += "</div>";
        sContent += "</div>";
        // 为调用后台sendMsg方法添加的bid属性
        sContent += "<input type='hidden' name='bid' id='bid' value='" + select_bid + "'/>";
        var infoWindow = new BMap.InfoWindow(sContent);  // 创建信息窗口对象
        mp.openInfoWindow(infoWindow, select_point);      // 打开信息窗口
    }
    //点击选中楼盘，地图自动移到楼盘处（待修改）

    function fang_cms_map(lnt, lat, bid, bname, path, address, phone1, discount, price) {
        select_point = new BMap.Point(lnt, lat);
        select_bid = bid;
        select_bname = bname;
        select_path = path;
        select_address = address;
        select_phone1 = phone1;
        select_discount = discount;
        select_price = price;
        mp.panTo(select_point);
        fang_cms_oncilck();
    }

</script>
<script type="text/javascript">
    var info = {$info};
    if(info){
        HousesAjax(info)
    }
    function HousesAjax(info) {
        var mapVal = info.map.split(',');
        var discount = info.group_discount ? info.group_discount : info.discount;
        fang_cms_map(mapVal[0], mapVal[1], info.id, info.title, info.img, info.address, info.tel, discount, info.average_price);
        $(".mapList").scrollTop(0);

        var txt = info.title, mouseoverTxt = txt + " " + info.average_price;
        var myCompOverlay = new ComplexCustomOverlay(mapVal[0], mapVal[1], info.title, mouseoverTxt, 1, info.id, info.address, info.img, info.tel, discount);
        mp.addOverlay(myCompOverlay);
    }

</script>
</body>
</html>